<template>
  <el-button class="my-button" :type="$props.type" v-text="$props.text" :disabled="$props.disabled" @click="execClick" v-show="visible"></el-button>
</template>

<script>
import RoleTools from '../Tools/RoleTools'

export default {
  name: 'MyButton',
  props:{
    text:String,
    disabled:Boolean,
    type:String,
    click:Function,
    accessAction:String,
  },
  data:function () {
    return {
      visible:true
    }
  },
  mounted () {
    // 检查访问权限
    this.visible=this.checkAccess()
  },
  methods:{
    execClick:function (params) {
      // console.log('params',params)

      if (typeof this.$props.click==='function'){
        // console.log('this.$props.click',this.$props.click)
        this.$props.click()
      }
    },
    // 检查权限
    checkAccess:function () {
      var currActionList = RoleTools.getActionList()
      // 超级管理员
      if ((currActionList.length===1 && currActionList[0]==='*') || currActionList==='["*"]') {
        return true
      }
      if (!this.$props.accessAction){
        return true
      }
      var actionArr = this.$props.accessAction.split(",")
      var isAllow=true
      actionArr.forEach(function (action, index) {
        if (currActionList.indexOf(action)===-1){
          isAllow=false
        }
      })
      return isAllow
    }
  }
}
</script>

<style scoped>

</style>
